import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import Layout from '../layout/index.vue'
import Home from '../views/home/index.vue'

interface IMyRoute {
  path: string
  name: string
  component: any,
  hidden: boolean,
  children?: Array<RouteRecordRaw | IMyRoute>
}

const LoginRoute: IMyRoute = {
  path: '/login',
  name: 'login',
  component: () => import('../views/login/index.vue'),
  hidden: true
}

export const routes: Array<RouteRecordRaw> = [
  // {
  //   path: '/login',
  //   name: 'login',
  //   component: () => import('../views/login/index.vue'),
  //   hidden: true
  // },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [
      {
        path: '/home',
        name: 'home',
        component: Home,
        meta: { icon: '', title: '系统首页' }
      }
    ]
  },
  {
    path: '/banner',
    component: Layout,
    redirect: '/banner/list',
    meta: { icon: '', title: '轮播图管理' },
    children: [
      {
        path: '/banner/list',
        name: 'banenrList',
        component: () => import('./../views/banner/index.vue'),
        meta: { icon: '', title: '轮播图列表' }
      },
      {
        path: '/banner/add',
        name: 'banenrAdd',
        component: () => import('./../views/banner/add.vue'),
        meta: { icon: '', title: '添加轮播图' }
      }
    ]
  },
  {
    path: '/pro',
    component: Layout,
    redirect: '/pro/list',
    meta: { icon: '', title: '产品管理' },
    children: [
      {
        path: '/pro/list',
        name: 'proList',
        component: () => import('./../views/pro/index.vue'),
        meta: { icon: '', title: '产品列表' }
      },
      {
        path: '/pro/seckill',
        name: 'seckill',
        component: () => import('./../views/pro/seckill.vue'),
        meta: { icon: '', title: '秒杀列表' }
      },
      {
        path: '/pro/recommend',
        name: 'recommend',
        component: () => import('./../views/pro/recommend.vue'),
        meta: { icon: '', title: '推荐列表' }
      },
      {
        path: '/pro/search',
        name: 'search',
        component: () => import('./../views/pro/search.vue'),
        meta: { icon: '', title: '筛选列表' }
      }
    ]
  },
  {
    path: '/user',
    name: 'user',
    component: Layout,
    redirect: '/user/list',
    meta: { icon: '', title: '账户管理' },
    children: [
      {
        path: '/user/list',
        name: 'userList',
        component: () => import('./../views/user/index.vue'),
        meta: { icon: '', title: '用户列表' }
      },
      {
        path: '/user/admin',
        name: 'adminList',
        component: () => import('./../views/user/admin.vue'),
        meta: { icon: '', title: '管理员列表' }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

// addRoute 方法可以配合权限做好左侧的菜单栏
router.addRoute(LoginRoute)

export default router
